﻿$(function() {
    $('#c').window({
        draggable: false,
        resizable: false,
        closed: true,
        width: 280,
        height: 380,
        cache: false,
        noheader: true,
        buttons: [
                {
                    text: 'Ok',
                    iconCls: 'icon-ok',
                    handler: function() {
                        alert('ok');
                    }
                },
                {
                    text: 'Cancel',
                    handler: function() {
                        $('#dd').dialog('close');
                    }
                }
            ]
    });

    $("#selectmore").click(function() {
        var countrytype=$("#countrytype").val();
        var selectType=true ;
        if(countrytype=="ebayaccount")
        {
          selectType =false;
          
        }
        $('#c').window('open');
        $("#t").datagrid({
            height: 335,
            title: '请选择...',
            nowrap: true,
            striped: false,
            url: "../../TableHanders.aspx?act=q&tid=1002&type=0" ,
            loadMsg: "正在加载,请稍后...",
            columns: [[
	                    { field: 'StatusId', title: 'Checked', checkbox: true },
                        { title: 'CountryName', field: 'CountryName', width: 200 }
                        ]],
            singleSelect:selectType,
            queryParams: {
                "countrytype":countrytype ,
                "countryNames": $("#txtCountryNames").val()
            },
            onLoadSuccess: function() {
                var rows = $("#t").datagrid('getRows');
                for (var i = 0; i < rows.length; i++) {
                    if (rows[i].StatusId == "Selected") {
                        $("#t").datagrid('selectRow', i);
                    }
                }
            }
        });
    });
    $("#btnClose").click(function() {
        $('#c').window('close');
    })
    $("#btnOK").click(function() {
        var ids = [];
        var rows = $('#t').datagrid('getSelections');
        for (var i = 0; i < rows.length; i++) {
            ids.push(rows[i].CountryName);
        }
        $("#txtCountryNames").val(ids.join(','));
        $('#c').window('close');
    });
});